<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新型农业主体列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>机构名称：</label>
                            <input name="deptId" type="hidden" id="treeId"/>
                            <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text"
                                   placeholder="请选择归属机构" autocomplete="off">
                        </li>
                        <li>
                            <label>营销人员：</label>
                            <input type="text" name="userName"/>
                        </li>
                        <li>
                            <label>客户姓名：</label>
                            <input type="text" name="agrCustName"/>
                        </li>
                        <li>
                            <label>农业类型：</label>
                            <select name="agrType" th:with="type=${@dict.getType('ecard_agriculture_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>时间排序：</label>
                            <select name="sortTime" th:with="type=${@dict.getType('ecard_sort_time')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>是否释放：</label>
                            <select name="releaseSts" >
                                <option value="">所有</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </li>
                        <li>
                            <label>是否拜访：</label>
                            <select name="visitSts" >
                                <option value="">所有</option>
                                <option value="已拜访">已拜访</option>
                                <option value="未拜访">未拜访</option>
                            </select>
                        </li>
                        <li>
                            <label>天眼查：</label>
                            <select name="tycsts" >
                                <option value="">所有</option>
                                <option value="已调用">已调用</option>
                                <option value="未调用">未调用</option>
                            </select>
                        </li>
                        <li>
                            <p>农业状态：</p>
                            <select name="state" th:with="type=${@dict.getType('sys_sts')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-date">
                            <label>创建日期： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" readonly
                                   name="params[startDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" readonly
                                   name="params[endDate]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">

            <a class="btn btn-primary multiple disabled" onclick="handOver()"
               shiro:hasPermission="merchant:agriculture:handOver">
                <i class="fa fa-exchange"></i> 转交
            </a>
            <a class="btn btn-success multiple disabled" onclick="release()"
               shiro:hasPermission="merchant:agriculture:handOver">
                <i class="fa fa-hourglass-end"></i> 释放
            </a>
            <a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="merchant:agriculture:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary multiple disabled" onclick="enable()"
               shiro:hasPermission="merchant:agriculture:switchOver">
                <i class="fa fa-plus"></i> 启用
            </a>
            <a class="btn btn-danger multiple disabled" onclick="disable()"
               shiro:hasPermission="merchant:agriculture:switchOver">
                <i class="fa fa fa-remove"></i> 停用
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="agricultureList"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>

<script th:inline="javascript">
    var visitFlag = [[${@permission.hasPermi('merchant:info:visit')}]];
    var partFlag = [[${@permission.hasPermi('merchant:info:part')}]];
    var agrFlag = [[${@permission.hasPermi('merchant:agriculture:view')}]];
    var prefix = ctx + "merchant/agriculture";
    var agricultureTypeDatas = [[${@dict.getType('ecard_agriculture_type')}]];
    var commonYesNoDatas = [[${@dict.getType('common_yes_no')}]];
    var agricultureMaritalDatas = [[${@dict.getType('ecard_agriculture_marital')}]];
    var agricultureResidentialDatas = [[${@dict.getType('ecard_agriculture_residential')}]];
    var businessProjectDatas = [[${@dict.getType('ecard_agriculture_business_project')}]];
    var businessTagDatas = [[${@dict.getType('ecard_agriculture_business_tag')}]];
    var agricultureTagDatas = [[${@dict.getType('ecard_agriculture_tag')}]];
    var agriculturelevelDatas = [[${@dict.getType('ecard_agriculture_level')}]];
    var sysStsDatas = [[${@dict.getType('sys_sts')}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            id: "agricultureList",
            modalName: "新型农业主体信息",
            pageList: [10, 20, 50, 100, 'All'],  //设置可供选择的页面记录数。 All显示所有记录
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '新型农业主体主键ID',
                    visible: false
                },
                {
                    field: 'agrGridArea',
                    title: '网格区域'
                },
                {
                    field: 'agrType',
                    title: '农业主体类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(agricultureTypeDatas, value);
                    }
                },
                {
                    field: 'agrCustName',
                    title: '客户姓名'
                },
                {
                    field: 'agrCustIdcard',
                    title: '身份证号'
                },
                {
                    field: 'agrIdcardHead',
                    title: '身份证头像面',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.agrIdcardHead, 300, 500);
                    }
                },
                {
                    field: 'agrIdcardBadge',
                    title: '身份证国徽面',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.agrIdcardBadge, 300, 500);
                    }
                },
                {
                    field: 'agrCustPhone',
                    title: '联系方式'
                },
                {
                    field: 'agrIsHouseholder',
                    title: '是否户主',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(commonYesNoDatas, value);
                    }
                },
                {
                    field: 'agrMaritalStatus',
                    title: '婚姻状况',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(agricultureMaritalDatas, value);
                    }
                },
                {
                    field: 'agrResidentialStatus',
                    title: '居住状况',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(agricultureResidentialDatas, value);
                    }
                },
                {
                    field: 'agrResidentialAddress',
                    title: '居住住址',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, "open");
                    }
                }/*,
                {
                    field: 'agrLicensePic',
                    title: '营业执照图片',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.agrLicensePic, 300, 500);
                    }
                },
                {
                    field: 'agrLicenseName',
                    title: '营业执照名称'
                }*/,
                {
                    field: 'agrBusinessProject',
                    title: '经营项目',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(businessProjectDatas, value);
                    }
                }/*,
                {
                    field: 'agrBusinessAddress',
                    title: '经营地址'
                }*/,
                {
                    field: 'agrMapAddress',
                    title: '地图地址',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, "open");
                    }
                },
                {
                    field: 'agrBusinessPic',
                    title: '经营照片',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.agrBusinessPic, 300, 500);
                    }
                },
                {
                    field: 'agrMarketingFocus',
                    title: '营销重点',
                    formatter: function (value, row, index) {
                        var array = [];
                        var val='';
                        if(value != null ){
                            array = value.split(",");
                        }
                        for(var i=0;i<array.length;i++){
                            if(i < array.length -1){
                                val+=$.table.selectDictLabel(businessTagDatas, array[i])+','
                            }else{
                                val+=$.table.selectDictLabel(businessTagDatas, array[i])+' '
                            }
                        }
                        return val;
                    }
                },
                {
                    field: 'agrBusinessLabel',
                    title: '业务标签',
                    formatter: function (value, row, index) {
                        var array = [];
                        var val='';
                        if(value != null ){
                            array = value.split(",");
                        }
                        for(var i=0;i<array.length;i++){
                            if(i < array.length -1){
                                val+=$.table.selectDictLabel(businessTagDatas, array[i])+','
                            }else{
                                val+=$.table.selectDictLabel(businessTagDatas, array[i])+' '
                            }
                        }
                        return val;
                    }
                },
                {
                    field: 'agrLabel',
                    title: '客户标签',
                    formatter: function (value, row, index) {
                        var array = [];
                        var val='';
                        if(value != null ){
                            array = value.split(",");
                        }
                        for(var i=0;i<array.length;i++){
                            if(i < array.length -1){
                                val+=$.table.selectDictLabel(agricultureTagDatas, array[i])+','
                            }else{
                                val+=$.table.selectDictLabel(agricultureTagDatas, array[i])+' '
                            }
                        }
                        return val;
                    }
                },
                {
                    field: 'agrLevel',
                    title: '客户层级',
                    formatter: function (value, row, index) {
                        var array = [];
                        var val='';
                        if(value != null ){
                            array = value.split(",");
                        }
                        for(var i=0;i<array.length;i++){
                            if(i < array.length -1){
                                val+=$.table.selectDictLabel(agriculturelevelDatas, array[i])+','
                            }else{
                                val+=$.table.selectDictLabel(agriculturelevelDatas, array[i])+' '
                            }
                        }
                        return val;
                    }
                },
                {
                    field: 'tycsts',
                    title: '天眼查结果'
                },
                {
                    field: 'visitSts',
                    title: '拜访结果'
                },
                {
                    field: 'maxbftime',
                    title: '最近拜访时间'
                },
                {
                    field: 'maxvisitpic',
                    title: '最近拜访照片',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var imgUrl = '';
                        if (value != '' && value != null && value != 'null' && value != undefined){
                            var picsplit = value.split(',');
                            for (var picsplitKey in picsplit) {
                                imgUrl += '<img class="img-circle img-xs" data-height="300" data-width="500" data-target="self" src="' +picsplit[picsplitKey] + '"/>'
                            }
                        }
                        return imgUrl;
                    }
                },
                {
                    field: 'remark',
                    title: '备注说明'
                },
                {
                    field: 'creationTime',
                    title: '创建时间'
                },
                {
                    field: 'userName',
                    title: '客户经理'
                },
                {
                    field: 'state',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'deptName',
                    title: '归属机构'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + visitFlag + '" href="javascript:void(0)" onclick="merchantVisit(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>拜访记录</a> ');
                        actions.push('<a class="btn btn-success btn-xs '  + partFlag + '" style="margin-top: 5px" href="javascript:void(0)" onclick="merchantPart(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>新型农业主体成员</a> ');
                        if (row.tycsts == '已调用') {
                            actions.push('<a class="btn btn-success btn-xs ' + agrFlag + '" style="margin-top: 5px" href="javascript:void(0)" onclick="agricultureMore(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>更多信息</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    /* 选择机构树 */
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSub
        };
        $.modal.openOptions(options);
    }

    function doSub(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function reset() {
        $('#treeId').val('')
        $.form.reset();
    }


    //转交新型农业主体
    function handOver() {
        var rows = $.table.selectFirstColumns();
        var url = prefix + '/handOver/' + rows.join();
        var options = {
            title: '选择客户经理',
            width: 900,
            height: 700,
            url: url,
            callBack: doSubmit
        };
        $.modal.confirm("确认要移交选中的【" + rows.length + "】个新型农业主体吗?", function () {
            $.modal.openOptions(options);
        });

    }

    function doSubmit(index, layero) {
        var result = layero.find("iframe")[0].contentWindow.submitHandler();
        if (result) {
            setTimeout("$.table.refresh()",600);
            $.modal.close(index);
            $.modal.msgSuccess("新型农业主体转交成功！");

        }
    }

    //释放客户
    function release() {
        var rows = $.table.selectFirstColumns();
        $.modal.confirm("确认要释放选中的【" + rows.length + "】个新型农业主体吗?", function () {
            var data = {"ids": rows.join()};
            $.operate.submit(prefix + "/release", "post", "json", data);
        });
    }

    function exportExcel(){
        var dataParam = $("#formId").serializeArray();
        var ids = $.table.selectColumns("id");
        var tipMsg = "确定导出所有数据吗？";
        if($.common.isNotEmpty(ids)){
            tipMsg = "确定导出勾选" + ids.length + "条数据吗？";
            dataParam.push({ "name": "ids", "value": ids });
        }
        dataParam = JSON.stringify(dataParam);
        $.modal.confirm(tipMsg, function() {
            window.location.href = prefix + "/export/" + dataParam;
        });
    }
    //拜访记录
    function merchantVisit(id) {
        var url = 'merchant/info/visit/' + id + '/4';
        $.modal.openTab("拜访记录", url);
    }

    //新型农业主体成员
    function merchantPart(id) {
        var url = 'merchant/info/part/' + id + '/4';
        $.modal.openTab("新型农业主体成员", url);
    }

    //跳转新型农业主体更多信息
    function agricultureMore(id) {
        var url = 'merchant/agriculture/agricultureTyc/' + id;
        $.modal.open("新型农业主体工商信息", url, '1000', '600');
    }

    /* 状态显示 */
    function statusTools(row) {
        if (row.state == 0) {
            // return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            return '<i class=\"fa fa-toggle-off text-info fa-2x\"></i> ';
        } else {
            // return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            return '<i class=\"fa fa-toggle-on text-info fa-2x\"></i> ';
        }
    }
    /* 停用 */
    function disable() {
        var rows = $.table.selectFirstColumns();
        $.modal.confirm("确认要停用选中的【" + rows.length + "】个新型农业主体吗?", function () {
            var data = {"ids": rows.join(), "state": 0};
            $.operate.submit(prefix + "/switchOver", "post", "json", data);
        });
    }

    /* 启用 */
    function enable() {
        var rows = $.table.selectFirstColumns();
        $.modal.confirm("确认要启用选中的【" + rows.length + "】个新型农业主体吗?", function () {
            var data = {"ids": rows.join(), "state": 1};
            $.operate.submit(prefix + "/switchOver", "post", "json", data);
        });
    }

</script>
</body>
</html>